
package net.vinote.smart.platform.service.action;

import java.sql.SQLException;

import net.vinote.smart.platform.comm.PlatformConst;
import net.vinote.smart.platform.module.database.DBManager;
import net.vinote.smart.platform.module.database.DBManagerFactory;
import net.vinote.smart.platform.module.database.Table;
import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.SRE;
import net.vinote.smart.platform.service.util.AutoInjection;


public class DataWindowPageAction
{
	@AutoInjection
	private String pagePath;

	/**
	 * 页面复制
	 * 
	 * @return
	 * @throws SQLException
	 */
	public String doCopy() throws SQLException
	{
		DBManager bm = DBManagerFactory.getInstance("datawindow_page");
		BizObject bo = bm
				.createQuery(
						SRE.getAttribute(
								PlatformConst.SRE_PREFIX_TABLE
										+ "datawindow_page", Table.class)
								.getFieldsName(), "pagePath=?")
				.setParamVal(pagePath).getSingleResult();
		bo.setAttribute("pagePath", pagePath + "_copy");
		bm.saveBizObject(bo);
		return PlatformConst.SUCCESS;
	}

	/**
	 * 删除一张页面
	 * 
	 * @return
	 * @throws SQLException
	 */
	public String doDelete() throws SQLException
	{
		DBManager bm = DBManagerFactory.getInstance("datawindow_page");
		int effectRow = bm.deleteWhereSql("pagePath=?", pagePath);
		return effectRow == 1 ? PlatformConst.SUCCESS : PlatformConst.FAIL;
	}
}
